package com.atwisdom.star.serviceController.production;

import com.alibaba.fastjson.JSONObject;
import com.atwisdom.star.common.vo.ActionData;
import com.atwisdom.star.common.vo.ResultInfo;
import com.atwisdom.star.exception.pojo.BusinessException;
import com.atwisdom.star.log.aop.StarAnnotation;
import com.atwisdom.star.service.production.impl.MasterPlanServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName: MasterPlanServiceController
 * @Description:主计划
 * @author:王红艳
 * @date: 2024/05/27 14:39
 */
@RestController
@RequestMapping("/production")
public class MasterPlanServiceController {
    @Autowired
    private MasterPlanServiceImpl masterPlanService;

    /**
     * 新增生产计划
     * @param data 计划数据
     * @return 计划数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addProductionPlan")
    public ResultInfo<?> addProductionPlan(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.addProductionPlan(data);
    }

    /**
     * 查询计划数据，并将hier下的数据对应的values查询出来放入
     * @param data 计划数据
     * @return 处理后的计划数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/queryProductionPlanAndHier")
    public ResultInfo<?> queryProductionPlanAndHier(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.queryProductionPlanAndHier(data);
    }

    /**
     * 订单分页查询，过滤掉被占用的数据
     * @param actionData 分页查询参数
     * @return 分页数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/querySalesOrderNotLinkByPage")
    public ResultInfo<?> querySalesOrderNotLinkByPage(@RequestBody JSONObject actionData)  throws BusinessException {
        return masterPlanService.querySalesOrderNotLinkByPage(actionData);
    }

    /**
     * 计划绑定订单，并更新订单状态
     * @param actionData 参数
     * @return 绑定数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addSalesOrderLinkToProductionPlan")
    public ResultInfo<?> addSalesOrderLinkToProductionPlan(@RequestBody ActionData<JSONObject> actionData)  throws BusinessException {
        return masterPlanService.addSalesOrderLinkToProductionPlan(actionData);
    }

    /**
     * 计划解除绑定订单，并更新订单状态
     * @param actionData 参数
     * @return 解绑是否成功标识
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/deleteSalesOrderLinkToProductionPlan")
    public ResultInfo<?> deleteSalesOrderLinkToProductionPlan(@RequestBody JSONObject actionData)  throws BusinessException {
        return masterPlanService.deleteSalesOrderLinkToProductionPlan(actionData);
    }

    /**
     * 更新计划状态
     * @param data 计划数据
     * @return 更新后数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/updateProductionPlanStatus")
    public ResultInfo<?> updateProductionPlanStatus(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.updateProductionPlanStatus(data);
    }

    /**
     * 审批计划
     * data示例：{"pointer":{"className":"","type":"","id":""},"approveValues":{"operatorId":"","operatorName":"","operateTime":"","action":"","status":"","opinions":""}}
     * @param data
     * @return
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/approveProductionPlan")
    public ResultInfo<?> approveProductionPlan(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.approveProductionPlan(data);
    }

    /**
     * 更新需求订单数据
     * @param data 需求订单数据
     * @return 更新后数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/updateRequireSalesOrder")
    public ResultInfo<?> updateRequireSalesOrder(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.updateRequireSalesOrder(data);
    }

    /**
     * 新增子计划
     * @param data 计划数据
     * @return 计划数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addRouting")
    public ResultInfo<?> addRouting(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.addRouting(data);
    }

    /**
     * 处理工艺路径的workCenter
     * @param data 计划数据
     * @return 计划数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/dealRoutingWorkCenter")
    public ResultInfo<?> dealRoutingWorkCenter(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.dealRoutingWorkCenter(data);
    }

    /**
     * 计划分页查询
     * @param actionData 分页查询参数
     * @return 返回分页查询routing数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/planQueryByPage")
    public ResultInfo<?> planQueryByPage(@RequestBody ActionData<JSONObject> actionData)  throws BusinessException {
        return masterPlanService.planQueryByPage(actionData);
    }

    /**
     * 初始化工艺路径
     * @param data 计划数据
     * @return 计划数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/initRouting")
    public ResultInfo<?> initRouting(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.initRouting(data);
    }

    /**
     * 根据工艺路径ID获取工作中心
     * @param data 工艺路径ID
     * @return 工作中心实例列表
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/getWorkCenterByRoutingId")
    public ResultInfo<?> getWorkCenterByRoutingId(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.getWorkCenterByRoutingId(data);
    }

    /**
     * 删除计划
     * @param data 计划id和工艺路径id
     * @return 返回
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/deletePlan")
    public ResultInfo<?> deletePlan(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.deletePlan(data);
    }

    /**
     * 执行计划
     * @param data 计划数据
     * @return 返回
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/executePlan")
    public ResultInfo<?> executePlan(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.executePlan(data);
    }

    /**
     * 添加生产通知单
     * @param data 生产通知单数据
     * @return 生产通知单数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addWorkNotice")
    public ResultInfo<?> addWorkNotice(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.addWorkNotice(data);
    }

    /**
     * 执行下发生产通知单
     * @param data 生产通知单数据
     * @return 生产通知单数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/executeWorkNotice")
    public ResultInfo<?> executeWorkNotice(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.executeWorkNotice(data);
    }

    /**
     * 工单开工
     * @param data 工单数据
     * @return 工单数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/startWorkNotice")
    public ResultInfo<?> startWorkNotice(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.startWorkNotice(data);
    }

    /**
     * 工单完工
     * @param data 工单数据
     * @return 工单数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/endWorkNotice")
    public ResultInfo<?> endWorkNotice(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.endWorkNotice(data);
    }

    /**
     * 分页查询，过滤掉被占用的数据
     * @param actionData 分页查询参数
     * @return 分页数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/queryTankNotLinkByPage")
    public ResultInfo<?> queryTankNotLinkByPage(@RequestBody JSONObject actionData)  throws BusinessException {
        return masterPlanService.queryTankNotLinkByPage(actionData);
    }

    /**
     * 增加领退料记录
     * @param data 领退料记录
     * @return 领退料记录数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addMaterialRecord")
    public ResultInfo<?> addMaterialRecord(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.addMaterialRecord(data);
    }

    /**
     * 增加报工记录
     * @param data 报工记录
     * @return 报工记录数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/addWorkReportRecord")
    public ResultInfo<?> addWorkReportRecord(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.addWorkReportRecord(data);
    }

    /**
     * 提交报工记录
     * @param data 报工记录
     * @return 报工记录数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/submitWorkReportRecord")
    public ResultInfo<?> submitWorkReportRecord(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.submitWorkReportRecord(data);
    }

    /**
     * 删除报工记录
     * @param data 报工记录
     * @return 报工记录数据
     * @throws BusinessException
     */
    @StarAnnotation
    @PostMapping("/deleteWorkReportRecord")
    public ResultInfo<?> deleteWorkReportRecord(@RequestBody JSONObject data)  throws BusinessException {
        return masterPlanService.deleteWorkReportRecord(data);
    }
}
